package com.cdks.wuxiu.api.service.mysql;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cdks.wuxiu.api.mapper.UserStatisInfoMapper;
import com.cdks.wuxiu.entity.mysql.UserStatisInfo;

import org.springframework.stereotype.Service;

/**
 * 用户统计信息 服务实现类
 */
@Service
public class UserStatisInfoServiceImpl extends ServiceImpl<UserStatisInfoMapper, UserStatisInfo> implements UserStatisInfoService {

    @Override
    public int init(long userId) {
        UserStatisInfo statisInfo = new UserStatisInfo();
        statisInfo.setUserId(userId);

        int ret  = baseMapper.insert(statisInfo);
        if (ret > 0)
        {
            return 0;
        }

        log.error("init user wallet failed: userId = " + userId + ", ret = " + ret);

        return -1;
    }

    @Override
    public UserStatisInfo getByUserId(long userId) {
        QueryWrapper<UserStatisInfo> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(UserStatisInfo::getUserId, userId);
        
        return baseMapper.selectOne(wrapper);
    }

    @Override
    public int addScoreCount(long userId, int score) {
        int ret  = baseMapper.addScoreCount(userId, score);
        if (ret == 1)
        {
            return 0;
        }

        log.error("addScoreCount failed: userId = " + userId + ", ret = " + ret);

        return -1;
    }

    @Override
    public int addVideoPlayCount(long videoId) {
        int ret  = baseMapper.addVideoPlayCount(videoId);
        if (ret == 1)
        {
            return 0;
        }

        log.error("addVideoPlayCount failed: videoId = " + videoId + ", ret = " + ret);

        return -1;
    }

    @Override
    public int addFansCount(long userId) {
        int ret  = baseMapper.addFansCount(userId);
        if (ret == 1)
        {
            return 0;
        }

        log.error("addFansCount failed: userId = " + userId + ", ret = " + ret);

        return -1;
    }

    @Override
    public int decFansCount(long userId) {
        int ret  = baseMapper.decFansCount(userId);
        if (ret == 1)
        {
            return 0;
        }

        log.error("decFansCount failed: userId = " + userId + ", ret = " + ret);

        return -1;
    }
}